/**
 * 
 */
package com.arx.character;

import com.arx.common.GlobalConsts;
import com.arx.interactive.InteractiveObject;
import com.arx.interactive.data.BehaviorData;

/**
 * @author Donald
 *
 */
abstract class NPCBehaviorBase implements NPCBase {
	// Sets a new behaviour for NPC
	//-----------------------------------------------------------------------------------------------
	// VERIFIED (Cyril 2001/10/15)
	//***********************************************************************************************
	public final void ARX_NPC_Behaviour_Change(final InteractiveObject io, 
			final int behavior, long behavior_param) {
		/*
		if ((!io)
		        ||	(!(io->ioflags & IO_NPC)))
			return;

		if ((io->_npcdata->behavior & BEHAVIOUR_FIGHT) && !(behavior & BEHAVIOUR_FIGHT))
		{
			ANIM_USE * ause1 = &io->animlayer[1];
			AcquireLastAnim(io);
			FinishAnim(io, ause1->cur_anim);
			ause1->cur_anim = NULL;
		}

		if ((behavior & BEHAVIOUR_NONE) || (behavior == 0))
		{
			ANIM_USE * ause0 = &io->animlayer[0];
			AcquireLastAnim(io);
			FinishAnim(io, ause0->cur_anim);
			ause0->cur_anim = NULL;
			ANIM_Set(ause0, io->anims[ANIM_DEFAULT]);
			ause0->flags &= ~EA_LOOP;

			ANIM_USE * ause1 = &io->animlayer[1];
			AcquireLastAnim(io);
			FinishAnim(io, ause1->cur_anim);
			ause1->cur_anim = NULL;
			ause1->flags &= ~EA_LOOP;

			ANIM_USE * ause2 = &io->animlayer[2];
			AcquireLastAnim(io);
			FinishAnim(io, ause2->cur_anim);
			ause2->cur_anim = NULL;
			ause2->flags &= ~EA_LOOP;


		}

		if (behavior & BEHAVIOUR_FRIENDLY)
		{
			ANIM_USE * ause0 = &io->animlayer[0];
			AcquireLastAnim(io);
			FinishAnim(io, ause0->cur_anim);
			ANIM_Set(ause0, io->anims[ANIM_DEFAULT]);
			ause0->altidx_cur = 0;
		}

		io->_npcdata->behavior = behavior;
		io->_npcdata->behavior_param = (float)behavior_param;
		*/
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public final void ARX_NPC_Behaviour_Reset(final InteractiveObject io) {
		if (io != null
				&& io.hasIoFlag(GlobalConsts.IO_NPC)
				&& io.hasNpcData()) {
			io.getNpcdata().setBehavior(GlobalConsts.BEHAVIOUR_NONE);
			for (byte i = 0; i < GlobalConsts.MAX_STACKED_BEHAVIOR; i++) {
				io.getNpcdata().getStackedBehavior(i).setExists(false);
			}
		}
	}
	// Stacks an NPC behaviour
	//-----------------------------------------------------------------------------------------------
	// VERIFIED (Cyril 2001/10/15)
	//***********************************************************************************************
	public final void ARX_NPC_Behaviour_Stack(final InteractiveObject io) {
		/*
		if (io != null
				&& io.hasIoFlag(GlobalConsts.IO_NPC)) {
			for (byte i = 0; i < GlobalConsts.MAX_STACKED_BEHAVIOR; i++) {
				BehaviorData bd = null;
				if (io.hasNpcData()) {
					bd = io.getNpcdata().getStackedBehavior(i);
				}
				if (bd != null && bd.exists()) {
					bd.setBehavior(io.getNpcdata().getBehavior());
					bd.setBehavior_param(io.getNpcdata().getBehavior_param());
					bd.setTactics(io.getNpcdata().getTactics());
					if (io->_npcdata->pathfind.listnb > 0)
						bd->target = io->_npcdata->pathfind.truetarget;
					else
						bd->target = io->targetinfo;
					bd.setMovemode(io.getNpcdata().getMovemode());
					bd.setExists(true);
					break;
				}
			}
		}
		*/
	}
	//***********************************************************************************************
	// Unstacks One stacked behaviour from an NPC
	//-----------------------------------------------------------------------------------------------
	// VERIFIED (Cyril 2001/10/15)
	//***********************************************************************************************
	public final void ARX_NPC_Behaviour_UnStack(final InteractiveObject io) {
		/*
		if ((!io)
		        ||	(!(io->ioflags & IO_NPC)))
			return;

		for (long i = MAX_STACKED_BEHAVIOR - 1; i >= 0; i--)
		{
			IO_BEHAVIOR_DATA * bd = &io->_npcdata->stacked[i];

			if (bd->exist)
			{
				AcquireLastAnim(io);
				io->_npcdata->behavior = bd->behavior;
				io->_npcdata->behavior_param = bd->behavior_param;
				io->_npcdata->tactics = bd->tactics;
				io->targetinfo = bd->target;
				io->_npcdata->movemode = bd->movemode;
				bd->exist = 0;
				ARX_NPC_LaunchPathfind(io, bd->target);

				if (io->_npcdata->behavior & BEHAVIOUR_NONE)
				{
					memcpy(io->animlayer, bd->animlayer, sizeof(ANIM_USE)*MAX_ANIM_LAYERS);
				}

				return;
			}
		}
		*/
	}
}
